--[[-----------------------------------------------------]]--
--	Draws a custom crosshair
--[[-----------------------------------------------------]]--
function GM:HUDCustomCrosshairDraw()

	--	Variables
	local ply			= LocalPlayer()
	local cust			= tobool( GetConVarNumber( "sc_custom_crosshair" ) )
	local pos			= ply:GetShootPos()
	local ang			= ply:EyeAngles()
	local aim			= ply:GetAimVector()
	local tr			= ply:GetEyeTraceNoCursor()
	local dist			= 300
	local chr			= ( pos + aim * 300 ):ToScreen()
	local sights		= false
	local firstp		= ply.FirstPerson
	
	--	Get irong sights
	if type( ply:GetActiveWeapon() ) == "Weapon" and ply:GetActiveWeapon().GetIronsights then
		sights			= ply:GetActiveWeapon():GetIronsights()
		cust			= cust and ( not sights )
	end
	
	--	Get real aim pos
	if tr.Hit then
		chr				= tr.HitPos:ToScreen()
		dist			= tr.HitPos:Distance( tr.StartPos )
	end
	
	--	Position of aim bar
	local mul			= ply:GetWalkSpeed() / 64
	if ply:KeyDown( IN_SPEED ) then mul = ply:GetRunSpeed() / 95 end
	if not tobool( GetConVarNumber( "sc_dynamic_crosshair" ) ) then
		mul				= 1
	end
	local sinx			= math.sin( CurTime() * 5 * mul )
	local siny			= math.cos( CurTime() * 10 * mul )
	if not tobool( GetConVarNumber( "sc_footstep_mvt" ) ) then
		sinx			= 0
		siny			= 0
	end
	local barx, bary	= 0, 0
	local cirx, ciry	= 0, 0
	
	--	Save sin
	if		ply:KeyDown( IN_FORWARD ) or
			ply:KeyDown( IN_BACK ) or
			ply:KeyDown( IN_MOVELEFT ) or
			ply:KeyDown( IN_MOVERIGHT )then
		ply.FootX		= sinx * 6
		ply.FootY		= siny * 4
		barx, bary		= chr.x + sinx * 7, chr.y + siny * 5
		cirx, ciry		= chr.x + sinx * 4, chr.y + siny * 2
	else
		ply.FootX		= 0
		ply.FootY		= 0
		barx, bary		= chr.x, chr.y
		cirx, ciry		= chr.x, chr.y
	end
	
	--	Don't draw crosshair if we shouldn't
	if not cust and firstp then return end
	
	--	FOV mul
	local fov			= ply:GetFOV()
	if not tobool( GetConVarNumber( "sc_dynamic_crosshair" ) ) then 
		fov				= 90
	end
	local fml			= ( fov / 25 )
	local min			= 4 * fml * math.pow( ( mul * 0.6 ), 3 )
	local max			= 10 * fml * math.pow( ( mul * 0.6 ), 3 )
	local cir			= 8

	--	Draw the crosshair
	surface.DrawCircle( cirx, ciry, cir * fml, Color( 0, 255, 0, 729000 / ( math.pow( fov, 3 ) ) ) )
	surface.DrawCircle( cirx + 1, ciry + 1, cir * fml, Color( 20, 20, 20, 729000 / ( math.pow( fov, 3 ) ) ) )
	surface.SetDrawColor( 125, 255, 125, 225 )
	surface.DrawLine( barx, bary - max, barx, bary - min )
	surface.DrawLine( barx, bary + max, barx, bary + min )
	surface.DrawLine( barx - max, bary, barx - min, bary )
	surface.DrawLine( barx + max, bary, barx + min, bary )
	surface.SetDrawColor( 125, 125, 125, 175 )
	surface.DrawLine( barx + 1, bary - max + 1, barx + 1, bary - min + 1 )
	surface.DrawLine( barx + 1, bary + max + 1, barx + 1, bary + min + 1 )
	surface.DrawLine( barx - max + 1, bary + 1, barx - min + 1, bary + 1 )
	surface.DrawLine( barx + max + 1, bary + 1, barx + min + 1, bary + 1 )

end